package com.ruoyi.backstage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zzw.domain.DatasourceManage;
import com.ruoyi.zzw.service.TDatasourceManageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据资源Controller
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/backstage/DataManage")
public class BackDatasourceManageController extends BaseController
{
    @Autowired
    private TDatasourceManageService tDatasourceManageService;

    /**
     * 查询数据资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(DatasourceManage datasourceManage)
    {
        startPage();
        List<DatasourceManage> list = tDatasourceManageService.selectTDatasourceManageList(datasourceManage);
        return getDataTable(list);
    }

    /**
     * 导出数据资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:export')")
    @Log(title = "数据资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DatasourceManage datasourceManage)
    {
        List<DatasourceManage> list = tDatasourceManageService.selectTDatasourceManageList(datasourceManage);
        ExcelUtil<DatasourceManage> util = new ExcelUtil<DatasourceManage>(DatasourceManage.class);
        util.exportExcel(response, list, "数据资源数据");
    }

    /**
     * 获取数据资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manage:query')")
    @GetMapping(value = "/{cResourceId}")
    public AjaxResult getInfo(@PathVariable("cResourceId") Long cResourceId)
    {
        return success(tDatasourceManageService.selectTDatasourceManageByCResourceId(cResourceId));
    }

    /**
     * 新增数据资源
     */
    @PreAuthorize("@ss.hasPermi('system:manage:add')")
    @Log(title = "数据资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DatasourceManage datasourceManage)
    {
        return toAjax(tDatasourceManageService.insertTDatasourceManage(datasourceManage));
    }

    /**
     * 修改数据资源
     */
    @PreAuthorize("@ss.hasPermi('system:manage:edit')")
    @Log(title = "数据资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DatasourceManage datasourceManage)
    {
        return toAjax(tDatasourceManageService.updateTDatasourceManage(datasourceManage));
    }

    /**
     * 删除数据资源
     */
    @PreAuthorize("@ss.hasPermi('system:manage:remove')")
    @Log(title = "数据资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cResourceIds}")
    public AjaxResult remove(@PathVariable Long[] cResourceIds)
    {
        return toAjax(tDatasourceManageService.deleteTDatasourceManageByCResourceIds(cResourceIds));
    }
}
